const http= require('http');
const ejs= require('ejs');
const url= require('url');

http.createServer(function (req, res) { 
    res.writeHead(200,'Content-Type:text/html;charset="utf8"')
    var pathname=url.parse(req.url).pathname
    if(pathname=='/login'){
        var getData='后台的数据'; 

        var _list =['aaa','bbb'];
        var h="<h2>我是H2</h2>"
        ejs.renderFile('views/login.ejs',{
            msg:getData,
            list:_list,
            h:h
        },(err,data)=>{
            console.log(err)
            res.end(data)
        });

    }else if (pathname=='/register') {
        res.end('register')
    }else{
        res.end('index')
    }
}).listen(8081);